package com.team12.hotel404.controller.collection;


import com.team12.hotel404.domain.Hotel;
import com.team12.hotel404.domain.collect;
import com.team12.hotel404.service.CollectService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;
import java.util.List;


@Controller
@RequestMapping("/Collection")
public class CollectController {
    @Autowired
    public CollectService collectService;


    @RequestMapping("/show")
    public String showCollection(Integer id, Model model){

        List<Hotel> hotels=collectService.findCollection(id);
        model.addAttribute("hotel",hotels);
        return "/user/collection";
    }

    @RequestMapping("/delete")
    @ResponseBody
    public String delete(@RequestParam("hotelId")Integer id){
        int i=collectService.delete(id);
        if (i>0){
            return "ok";
        }else {
            return "error";
        }
    }





    @RequestMapping("/add")
    @ResponseBody
    public String addCollection(@RequestParam("hotelId")Integer hotelId,@RequestParam("userId")Integer userId){
        collect collects=new collect();
        collects.setHotelId(hotelId);
        collects.setUserId(userId);
        int i=collectService.createCollection(collects);
        if (i>0){
            return "ok";
        }else{
            return "error";
        }
    }



}
